<?php
/**
 * 视图抽象
 *
 * @package if
 * @subpackage view
 * @since 1.0
 */
abstract class IAbstractView extends IObject implements IView {
	private $values = array();
	/**
	 * Enter description here...
	 *
	 * @var IController
	 */
	private $controller;
	
	private $opts = array();
	
	function put(array $values = null) {
		if ($values) {
			$this->values = array_merge($this->values, $values);
		}
	}
	
	function values() {
		return $this->values;
	}
	
	function setController($controller) {
		$this->controller = $controller;
	}
	
	/**
	 * Enter description here...
	 *
	 * @return IController
	 * @since 1.0
	 */
	function controller() {
		return $this->controller;
	}
	
	
	function tpl($ext = null) {
		$tpl = ltrim(if_name_to_c($this->controller->name()) . "/" . if_name_to_c($this->controller->action()->name()), "/");
		$tpl = str_replace(".", "/", $tpl);
		if (!$ext) {
			return $tpl;
		}
		else {
			return $tpl . "." . ltrim($ext, ".");
		}
	}
	
	function init($opts) {
		if (is_array($opts)) {
			$this->opts = $opts;
		}
	}
	
	function opt($name) {
		$value = isset($this->opts[$name])?$this->opts[$name]:null;
		if ($value) {
			$value = str_replace("%{locale}", IApplication::singleton()->locale()->name(), $value);
		}
		return $value;
	}
	
	function opts() {
		foreach ($this->opts as $name => $value) {
			$this->opts[$name] = $this->opt($name);
		}
		return $this->opts;
	}
	
	/**
	 * 设置选项
	 *
	 * @param string|array $nameOrOpts 选项名或者一组选项
	 * @param mixed $value 选项值
	 * @since 1.1.2
	 */
	function setOpt($nameOrOpts, $value = null) {
		if (is_array($nameOrOpts)) {
			$this->opts = array_merge($this->opts, $nameOrOpts);
		}
		else {
			$this->opts[$nameOrOpts] = $value;
		}
	}
}

?>